<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue3-escook</title>
  <link rel="stylesheet" href="./lib/style.css">
  <script type="importmap">
    {
      "imports" : {
        "vue": "./lib/vue-3.4.29.js"
      }
    }
  </script>
  <script type="module">
    import { createApp, ref } from 'vue'

    const app = createApp({
      setup() {
        const count = ref(0)
        const obj = ref({ name: 'zs' })

        const changeName = () => {
          obj.value.name = 'ls'
        }

        const add = () => {
          // 在 JS 区域，如果要修改 ref 响应式数据的值，
          // 必须通过 ref.value 进行修改
          count.value++
        }

        return {
          count,
          add,
          obj,
          changeName
        }
      }
    })

    app.mount('#app')
  </script>
</head>

<body>
  <div id="app">
    <h1>count 的值是：{{ count }}</h1>
    <button @click="add">+1</button>

    <hr>
    <!-- 在模板中访问 ref 数据，会自动进行解包，不必使用 .value 进行数据的访问 -->
    <p>name 的值是：{{ obj.name }}</p>
    <button @click="changeName">修改 name</button>
  </div>
</body>

</html>